package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.ErrorCodeEnum;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bean.vo.BackpaybillVO;
import com.jishuo.nontax.bfc.service.BackBillService;
import org.dom4j.Element;

/**
 * @author hlp
 * @date 2023/2/8 15:16
 * @Description:
 */
public class BackBillApi implements ApiHandle {
    @Override
    public BaseResult execute(String head, Element body) {
        if (head.equals("getBackbill")) { // 获取退付书单据信息
            String backbillnum = body.selectSingleNode("//root/body/backbillnum").getText();
            if(backbillnum==null||backbillnum.equals("")){
                return new BaseResult(ErrorCodeEnum.PARAM_ERR.getCode(), "参数为空[backbillnum]");
            }

            BackBillService backBillService = (BackBillService) SpringContextUtil.getBean("backBillService");
            return backBillService.getBackbill(backbillnum);

        } else if (head.equals("setBackBillDeposit")) { //  退付书单据缴费
            BackpaybillVO backpaybillVO = new BackpaybillVO();
            backpaybillVO.setBackbillnum(body.selectSingleNode("//root/body/backbillnum").getText());
            backpaybillVO.setDealdate(body.selectSingleNode("//root/body/paybankdt").getText());
            backpaybillVO.setBankaffirm(body.selectSingleNode("//root/body/bankaffirm").getText());
            backpaybillVO.setBankstation(body.selectSingleNode("//root/body/bankstation").getText());
            BackBillService backBillService = (BackBillService) SpringContextUtil.getBean("backBillService");
            BaseResult ret = backBillService.setBackBillDeposit(backpaybillVO, "00");
            int n = (ret.isSuccess()) ? 1 : 0;
            ret.setData("<returninfo>"+n+"</returninfo>");
            return ret;
        }
        return null;
    }
}
